<template>
  <div>
    <el-container>
      <el-header>
        <el-menu :default-active="$route.path" router
                 class="el-menu-demo" mode="horizontal">
          <el-menu-item index="/homepage">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/rescue">流浪动物救助中心</el-menu-item>
          <el-menu-item index="/oo">铲屎官指南</el-menu-item>
          <el-menu-item index="/register">注册</el-menu-item>
          <el-menu-item index="/adminLogin">登录</el-menu-item>
          <el-submenu index="" v-if="this.user.name!=null">
            <template slot="title" >
              <div style="display: flex">
                <div>
                  <el-avatar :src="'http://localhost:8080/yyj/files/'+this.user.avatar"></el-avatar>
                </div>
                <div style="margin-left: 7px">
                  {{user.name}}
                </div>
              </div>

            </template>
            <el-menu-item index="/mine">个人中心</el-menu-item>
            <el-menu-item @click="exit()">退出登录</el-menu-item>

          </el-submenu>
        </el-menu>
      </el-header>
    </el-container>
    <el-container class="scroll-container">
      <!--main    -->
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </div>

</template>


<script>
import request from "@/utils/request";

export default {
  name: "MainView",
  data() {
    return{
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      form: {}
    }
  },
  created() {
    // 默认选择 "首页" 导航链接
    this.$router.push('/homepage');

  },
  methods:{
    exit(){
      localStorage.removeItem("user");
      this.$router.push("/adminLogin")
    },
  }

}
</script>

<style scoped>
.scroll-container {
  height: 700px; /* 设置容器的高度，根据需要进行调整 */
  overflow-y: auto; /* 添加垂直滚动 */
}



</style>